import json
from common import read_config
from common.logget import logger
cof = read_config.Docof()
sys = cof.get_value_from_option("environment", "sys_name")


def log_info(title, url, method, header, info, respond):
    try:
        logger.info(
            f"""
                             _    _         _      _____         _
              __ _ _ __ (_)  / \\  _   _| |_ __|_   _|__  ___| |_
             / _` | '_ \\| | / _ \\| | | | __/ _ \\| |/ _ \\/ __| __|
            | (_| | |_) | |/ ___ \\ |_| | || (_) | |  __/\\__ \\ |_
             \\__,_| .__/|_/_/   \\_\\__,_|\\__\\___/|_|\\___||___/\\__|
                  |_|
                  开始执行{sys}项目...
                """
        )
        logger.info(f"==================================接口用例开始执行: {title}==================================")
        logger.info(f"接口请求标题>>>>>> {title}")
        logger.info(f"接口请求地址>>>>>> {url}")
        logger.info(f"接口请求类型>>>>>> {method}")
        logger.info(f"接口请求头  >>>>>> {header}")
        logger.info(f"接口请求正文>>>>>> {info['json']}")
        # logger.info(f"接口返回的text文本信息——>> {respond.text}")
        logger.info(f"接口实际结果<<<<<< {respond.json()}")

        exp = info['expected']
        b = []
        for i in exp:
            b.append(i)

        logger.info(f"接口断言信息 {b}")
    except (TypeError, json.JSONDecodeError) as e:
        logger.error(f'接口请求标题 ：【{title}】出错了,错误文本信息:{respond.text}')
        logger.error(e)




def result_log(apiname):
    # logger.error("\033[0;31m" + "-" * 120 + '\n| ' + "接口测试失败" + "\033[0m" + "\n" + "└" + "-" * 150)
    logger.info(f"接口测试结果>>>>>>   {apiname}  ---->>>>>>测试通过 <<<<<<")
    logger.info(f"==================================接口t用例执行结束: {apiname}==================================")
